{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "train=pd.read_csv('stacking_train.csv')\n",
    "test=pd.read_csv('stacking_test.csv')\n",
    "X_train=train[['pred','pred_2']].values\n",
    "y_train=train['rating']\n",
    "X_test=test[['pred','pred_2']].values\n",
    "y_test=test['rating']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from sklearn.linear_model import from sklearn.linear_model import LinearRegression\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()   # 初始化LogisticRegression\n",
    "lr.fit(X_train,y_train)   # 使用训练集对测试集进行训练\n",
    "lr_y_predit=lr.predict(X_test) \n",
    "test['stacking']=lr_y_predit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "线性回归stacking 的mse: 1.1398532765768226\n",
      "线性回归stacking 的mae: 0.8274140544423632\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "def get_mse(a,b):\n",
    "    return ((a-b)**2).mean()\n",
    "def get_mae(a,b):\n",
    "    return ((np.abs(a-b)).mean())\n",
    "print('线性回归stacking 的mse:',get_mse(test['rating'],test['stacking']))\n",
    "print('线性回归stacking 的mae:',get_mae(test['rating'],test['stacking']))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
